package sybel.pan;

import java.awt.Dialog.ModalityType;
import java.awt.Window;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import org.w3c.dom.Document;
import sybel.DomBuilder;

/**
 *
 * @author Stefano
 */
public class newBehav extends javax.swing.JPanel {

    /** Creates new form newBehav */
    public newBehav() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTextName = new javax.swing.JTextField();
        jButCancel = new javax.swing.JButton();
        jButDone = new javax.swing.JButton();
        jLabelDomain = new javax.swing.JLabel();
        jLabelID = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jTextID = new javax.swing.JTextField();
        jTextDomain = new javax.swing.JTextField();

        jTextName.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 0, 0), 2));

        jButCancel.setText("Cancel");
        jButCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButCancelActionPerformed(evt);
            }
        });

        jButDone.setText("Done");
        jButDone.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButDoneActionPerformed(evt);
            }
        });

        jLabelDomain.setText("*Domain:");

        jLabelID.setText("ID:");

        jLabel1.setText("*Name:");

        jTextDomain.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 0, 0), 2));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel1)
                            .addComponent(jLabelID))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jTextID, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 163, Short.MAX_VALUE)
                            .addComponent(jTextName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 163, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addComponent(jLabelDomain)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextDomain, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jButDone)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButCancel)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextDomain, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabelDomain))
                    .addComponent(jLabel1))
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelID))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButCancel)
                    .addComponent(jButDone))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButCancelActionPerformed
        dialog.dispose();// Chiude la finestra alla pressione del tasto Cancel
}//GEN-LAST:event_jButCancelActionPerformed

    private void jButDoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButDoneActionPerformed

        /*  Controllo sugli input   */
        if(jTextName.getText().isEmpty() || jTextDomain.getText().isEmpty()){
            JOptionPane.showMessageDialog(null, "The marked fields are required");
        }else{
            newbehaviour = DomBuilder.newBehaviourDocument(jTextName.getText(), jTextDomain.getText(),jTextID.getText());
            if (newbehaviour != null){
                dialog.dispose();
            }
        }
        
}//GEN-LAST:event_jButDoneActionPerformed


    public Document show(Window owner){
        dialog = new JDialog(owner,"New Behaviour",ModalityType.APPLICATION_MODAL);
        dialog.setContentPane(this);
        dialog.pack();
        dialog.setVisible(true);
        return newbehaviour;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButCancel;
    private javax.swing.JButton jButDone;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabelDomain;
    private javax.swing.JLabel jLabelID;
    private javax.swing.JTextField jTextDomain;
    private javax.swing.JTextField jTextID;
    private javax.swing.JTextField jTextName;
    // End of variables declaration//GEN-END:variables
    private javax.swing.JDialog dialog;
    private Document newbehaviour = null;
}
